// ApplicationWebPage.cpp: implementation of the CApplicationWebPage class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AUSlotsTester.h"
#include "ApplicationWebPage.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CApplicationWebPage::CApplicationWebPage()
{

}

CApplicationWebPage::~CApplicationWebPage()
{

}

void CApplicationWebPage::InsertDocumentRow( bool bShadeBackground, CAUSlotsTesterDoc* pDoc )
{
	const CSpinTestResults& results = pDoc->GetResults();

	COLORREF cr;

	if ( bShadeBackground )
	{
		cr = RGB( 0xE0, 0xE0, 0xE0 );
	}
	else
	{
		cr = RGB( 0xFF, 0xFF, 0xFF );
	}

	BeginRow();

		BeginColumn( cr );

			InsertContent( pDoc->GetSlotGutID() );

		EndColumn();

		BeginColumn( cr );

			CString strHREF;

			strHREF.Format( _T( "%08X" ), pDoc );

			BeginAnchor( strHREF );

				InsertContent( pDoc->GetTitle() );

			EndAnchor();

		EndColumn();

		BeginColumn( haRight, 2, cr );

			InsertContent( results.GetTotalPayoutPercent(), 3 );

			InsertContent( _T( "%" ) );

		EndColumn();

		BeginColumn( haRight, 2, cr );

			InsertContent( results.GetPaidLinesPlayed() );

		EndColumn();

		BeginColumn( haCenter, cr );

			CAUSlotsTesterDoc::SPIN_STATE ss = pDoc->GetSpinState();

			if ( ss == CAUSlotsTesterDoc::ssSpinning )
			{
				InsertContent( _T( "Spinning" ) );
			}
			else if ( ss == CAUSlotsTesterDoc::ssStopping )
			{
				InsertContent( _T( "Stopping" ) );
			}
			else
			{
				ASSERT( ss == CAUSlotsTesterDoc::ssStopped );
				InsertContent( _T( "Stopped" ) );
			}

		EndColumn();

	EndRow();
}

void CApplicationWebPage::GenerateContent()
{
	BeginDocument();

		BeginHead();

			BeginTitle();

				InsertContent( _T( "Slot Machine Spin Tester" ) );

			EndTitle();

		EndHead();

		BeginBody();

			BeginHeading( 3, haCenter );

				InsertContent( _T( "Slot Machines Currently Undergoing Spin Testing" ) );

			EndHeading( 3 );

			BeginTable( 100, true, 0 );

				BeginRow();

					BeginColumn( 100 );

						BeginBold();

							InsertContent( _T( "Gut ID" ) );

						EndBold();

					EndColumn();

					BeginColumn();

						BeginBold();
	
							InsertContent( _T( "Name" ) );

						EndBold();

					EndColumn();

					BeginColumn( 120, false, haRight );

						BeginBold();

							InsertContent( _T( "Payout" ) );

						EndBold();

					EndColumn();

					BeginColumn( 10 );
						
						InsertContent( _T( "&nbsp;" ) );

					EndColumn();

					BeginColumn( 140, false, haRight );

						BeginBold();
	
							InsertContent( _T( "Paid Lines" ) );

						EndBold();

					EndColumn();

					BeginColumn( 1 );
						
						InsertContent( _T( "&nbsp;" ) );

					EndColumn();

					BeginColumn( 120, false, haCenter );

						BeginBold();

							InsertContent( _T( "Status" ) );

						EndBold();

					EndColumn();

				EndRow();

				BeginRow();

					BeginColumn( 3, 7 );

					EndColumn();

				EndRow();

				POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();

				CDocTemplate* pdt = AfxGetApp()->GetNextDocTemplate( pos );

				pos = pdt->GetFirstDocPosition();

				bool bShadeBackground = true;
				bool bShowBottomLine = false;

				while ( pos )
				{
					CAUSlotsTesterDoc* pDoc = (CAUSlotsTesterDoc*)pdt->GetNextDoc( pos );

					if ( pDoc->GetSlotGutID() )
					{
						InsertDocumentRow( bShadeBackground, pDoc );

						bShowBottomLine = true;

						if ( bShadeBackground )
						{
							bShadeBackground = false;
						}
						else
						{
							bShadeBackground = true;
						}
					}
				}

				if ( bShowBottomLine )
				{
					BeginRow();

						BeginColumn( 3, 7 );

						EndColumn();

					EndRow();
				}

			EndTable();

		EndBody();

	EndDocument();
}
